package com.wn.servlet.resp;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author yellow Docter
 * @date 2022 -06-29
 * @desc
 *  resp 对象 还可以回写其他的数据
 *
 *  01  头信息
 *     回写其他的头信息:
 *       resp.setHeader("name","jack");  键值对的方式
 *
 *        resp.setContentType(""); 封装了有意义头信息
 *        setContentType  设置 数据类型/ 编码格式  可以解决乱码问题
 *
 *  02 可以设置响应码
 *
 *  03 回写json 字符串
 *
 *
 */
@WebServlet("/resp04")
public class Resp04Servlet extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

//        resp.setHeader("name","jack");
//        resp.setHeader("age","40");
//
//        resp.setContentType("text/html;charset=utf-8");
//        resp.getWriter().write("中奖了...500W");

//        resp.sendError(404,"不要找了,资源下架了....");


    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doGet(req, resp);
    }
}
